package com.umeox.watch.moto.dataservice.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.BatteryManager;

public class BatteryReceiver extends BroadcastReceiver {

	private int mBatteryLevel = -1;

	public BatteryReceiver(Context ctx) {
		super();
		ctx.registerReceiver(this, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
	}

	@Override
	public void onReceive(Context context, Intent batteryStatus) {
		int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
		int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
		float batteryPct = level * 100 / (float) scale;
		mBatteryLevel = (int) batteryPct;
	}

	public int getBatteryLevel() {
		return mBatteryLevel;
	}
}